//
//  SSUserInfoManager.m
//  starspaceVR
//
//  Created by 曹端芹 on 17/10/9.
//  Copyright © 2017年 starspace. All rights reserved.
//

#import "SSUserInfoManager.h"
#import "SSFileCacheManager.h"
#import "SSUserInfoModel.h"

static SSUserInfoManager *_singleton = nil;

@implementation SSUserInfoManager

+ (instancetype)sharedManager {
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        _singleton = [[SSUserInfoManager alloc] init];
    });
    return _singleton;

}

- (SSUserInfoModel *)currentUserInfo {
    id obj = [SSFileCacheManager getObjectByFileName:NSStringFromClass([SSUserInfoModel class])];
    if (obj != nil) {
        return obj;
    }
    return nil;
}
- (void)resetUserInfoWithUserInfo:(SSUserInfoModel *)userInfo {
    [userInfo archive];
}

- (void)didLoginInWithUserInfo:(id)userInfo {
    SSUserInfoModel *userinfo = [SSUserInfoModel modelWithDictionary:userInfo];
    [userinfo archive];
    
    [SSFileCacheManager saveUserData:@YES forKey:kSSHasLoginFlag];
}

- (void)didLoginOut {
    [SSFileCacheManager removeObjectByFileName:NSStringFromClass([SSUserInfoModel class])];
    [SSFileCacheManager saveUserData:@NO forKey:kSSHasLoginFlag];
}
// 判断是否是登陆状态
- (BOOL)isLogin {
    return [[NSUserDefaults standardUserDefaults] boolForKey:kSSHasLoginFlag];
}

@end
